<?php
/**
 * Contains basic methods needed for reporting
 *
 * This class contains the methods needed for getting the
 * XML data string and the execution driver.
 * @package Reports
 */

/**
 *
 */
require_once(AD_SERVER_PATH . '/pkgs/init.php');
require_once(AD_SERVER_PATH . '/pkgs/crypter.php');
require_once(AD_SERVER_PATH . '/pkgs/logger.php');
require_once(AD_SERVER_PATH . '/pkgs/server.php');
require_once(AD_SERVER_PATH . '/pkgs/utils.php');

/**
 * Contains basic methods needed for reporting
 *
 * This class contains the methods needed for getting the
 * XML data string and the execution driver.
 * @package Reporting
 */
class CReport
{
	/**
	 * Executes reporting
	 *
	 * Executes whichever child class is needed.
	 */
	public function execute()
	{
		$fmt = strtolower(CUtils::get_param('fmt'));
		switch ($fmt)
		{
			case 'pdf_listing':
				require_once(AD_SERVER_PATH . '/reports/pdf_listing.php');
				$obj = new CPDF_listing(AD_SERVER_PATH . '/templates/pdf/property_report.csv');
				$obj->get_report();
				CLogger::log('INFO', CCrypter::decrypt($_COOKIE['AD_RETS_U']), 'User requested PDF listing report.');
				break;

			case 'pdf_detail':
				require_once(AD_SERVER_PATH . '/reports/pdf_detail.php');
				$obj = new CPDF_detail();
				$obj->get_report();
				CLogger::log('INFO', CCrypter::decrypt($_COOKIE['AD_RETS_U']), 'User requested PDF detail report.');
				break;

			case 'pdf_test':
				require_once(AD_SERVER_PATH . '/reports/pdf_report.php');
				$obj = new CPDF_report(AD_SERVER_PATH . '/templates/pdf/property_report.csv');
				$obj->test();
				CLogger::log('INFO', CCrypter::decrypt($_COOKIE['AD_RETS_U']), 'User requested PDF test report.');
				break;

			case 'xml_mismo':
				require_once(AD_SERVER_PATH . '/reports/xml_mismo.php');
				$obj = new CXML_mismo(AD_SERVER_PATH . '/templates/xml/mismo.2_6.xsl', AD_SERVER_PATH . '/templates/xml/mismo.2_6.dtd');
				$obj->get_report();
				CLogger::log('INFO', CCrypter::decrypt($_COOKIE['AD_RETS_U']), 'User requested XML MISMO report.');
				break;

			case 'xml_detail':
				require_once(AD_SERVER_PATH . '/reports/xml_detail.php');
				$obj = new CXML_detail();
				$obj->get_report();
				CLogger::log('INFO', CCrypter::decrypt($_COOKIE['AD_RETS_U']), 'User requested XML detail report.');
				break;

			case 'img_export':
				require_once(AD_SERVER_PATH . '/reports/img_report.php');
				$obj = new CIMG_report();
				$obj->get_report();
				CLogger::log('INFO', CCrypter::decrypt($_COOKIE['AD_RETS_U']), 'User requested image report.');
				break;

			default:
				break;
		}
	}

	/**
	 * Gets XML data string
	 *
	 * Grabs XML data string using CServer class.
	 * @return string $xml
	 */
	protected function get_data()
	{
		$obj = new CServer();
		return $obj->get_list(true);
	}

	/**
	 * Gets address string
	 *
	 * Concats address together on one line,
	 * and returns it to caller.
	 * @param array $xml_row
	 * @return string $address
	 */
	protected function get_address($xml_row)
	{
		$address  = $xml_row->street_number	. ' '	. $xml_row->street_direction		. ' ' . $xml_row->street_name	. ' ';
		$address .= $xml_row->street_suffix . ' '	. $xml_row->street_post_direction	. ' ' . $xml_row->unit			. ' ';
		$address .= $xml_row->city	 		. ', '	. $xml_row->state					. ' ' . $xml_row->zip;

		return preg_replace('/\s+/', ' ', $address);
	}
}
